package web.exercise.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import web.exercise.Dao.ContactsDao;
import web.exercise.Dao.impl.ContactsDaoImpl;
import web.exercise.entity.Contacts;

public class ShowListServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html; charset=utf-8");
		//获取数据
		ContactsDao dao=new ContactsDaoImpl();
		List<Contacts> list=dao.getContactsList();
		//写入request域
		request.setAttribute("contactsList",list);
		//将uuid也放入session域中
		HttpSession session=request.getSession();
		String uuid=UUID.randomUUID().toString().replace("-","");
		session.setAttribute("uuid", uuid);
		//请求转发
		request.getRequestDispatcher("/showList.jsp").forward(request,response);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}

}
